# -*- coding: utf-8 -*-

import os
from ftplib import FTP as ftp

__author__ = 'Fonny'


def main():
	sHost = '192.168.2.1'
	sUser = 'admin'
	sPasswd = raw_input('Enter the passwd:')

	# 注意: getpass 必须在命令行下执行,不可用于 Pycharm 调试,但 Debug 可用
	# sPasswd = getpass.getpass()
	# print(sPasswd)

	if not sPasswd:
		exit()
	FILE = 'AutoHotkey.exe'

	# rpath = '/sda1/手机照片/IMG_0001.JPG'

	# upFilename = 'C8119_RT_AC68U_Manual.zip'
	# upFilehandle = open(upFilename)

	# con = ftp(host=sHost, user=sUser, passwd=sPasswd, acct=sAcct)
	con = ftp()
	try:
		con.connect(host=sHost, port='21')
		con.login(sUser, sPasswd)
		# con.login()
		con.cwd('/sda1/uploads')

		try:
			con.storbinary('STOR %s' % FILE, open(FILE, 'rb'))
		except Exception:
			print 'ERROR:cannot up file "%s"' % FILE
			os.unlink(FILE)
		#
		# rsize = con.size('IMG_0001.JPG')
		# print(rsize)
		# print(list)
	except Exception, Err:
		print(Err)
	finally:
		con.close()


if __name__ == '__main__':
	main()
